#include<bits/stdc++.h>
using namespace std;
int n,m,l,s,ans;
int d[100005],v[100005],a[100005];
long long tmpv;
int main(){
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	int t;
	cin>>t;
	while(t--){
		ans=0;
		tmpv=0;
		cin>>n>>m>>l>>s;
		for(int i=1;i<=n;i++){
			cin>>d[i]>>v[i]>>a[i];
			if(a[i]==0&&v[i]>s)ans++;
		}
		int las;
		for(int i=1;i<=m;i++){
			cin>>las;
		}
		for(int i=1;i<=n;i++){
			if(a[i]==0&&v[i]>s&&d[i]>las){
				ans--;
				continue;
			}
			else if(a[i]==0)continue;
			else if(a[i]>0&&d[i]<=las){
				tmpv=1ll*v[i]*v[i]+1ll*a[i]*2*(las-d[i]);
				if(tmpv>1ll*s*s)ans++;
			}
		}
		cout<<ans<<" "<<m-1<<endl;
	}
	return 0;
}
